﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmoLiteApi.Sql;
using System.Data.SqlClient;
using SmoLiteApi.Helper;

namespace SmoLiteApi
{
    /// <summary/>
    public class DatabaseRole
    {
        private Database _database;
        private string _name;

        /// <summary/>
        public DatabaseRole(
            Database database,
            string name)
        {
            this._database = database;
            this._name = name;
        }

        /// <summary/>
        public void Create()
        {
            RoleCreateSql roleCreateSql = new RoleCreateSql();

            // set attributes
            roleCreateSql.AddObject(new { Name = this._name });

            using (SqlCommandHelper sqlCommandHelper = SqlCommandHelper.FetchSqlCommand(this._database.SqlConnection, roleCreateSql.Render()))
            {
                // run the command
                sqlCommandHelper.ExecuteNonQuery();
            }
        }

        /// <summary/>
        public string Name
        {
            get { return this._name; }
            set { this._name = value; }
        }
    }
}
